package com.project.interceptor;

import com.project.bean.UserBean;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 管理员拦截器
 */
@Component
public class ManagerInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //得到登陆信息
        UserBean loginUser = (UserBean)request.getSession()
                .getAttribute("loginUser");
        if(loginUser != null && "管理员".equals(loginUser.getLevel())){
            return true;
        }
        response.sendRedirect("/login.html?loginError=noManager");
        return false;
    }
}